package controller.trafficlights;

import simulator.enums.Direction;
import simulator.enums.LaneType;

public class PedestrianLight extends TrafficLight
{
	private final int MAX_GREEN_TIME = 12000;
	private final int MAX_YELLOW_TIME = 6000;
	
	public PedestrianLight(Direction direction, LaneType type)
	{
		_direction = direction;
		_type = type;
		_state = TrafficLightState.red;
		_isActive = false;
	}
	
	@Override
	public void updatePriority(long elapsedTime) 
	{
		//No need to be implemented here.
	}

	@Override
	public void update(long elapsedTime) 
	{
		_elapsedTime += elapsedTime;
		
		if(_state == TrafficLightState.red)
		{
			if(isOccupied())
			{
				changeState(TrafficLightState.green);
				_elapsedTime = 0;
			}
		}
		else if(_state == TrafficLightState.green)
		{
			if(_elapsedTime >= MAX_GREEN_TIME)
			{
				changeState(TrafficLightState.yellow);
				_elapsedTime = 0;
			}
		}
		else if(_state == TrafficLightState.yellow)
		{
			if(_elapsedTime >= MAX_YELLOW_TIME)
			{
				changeState(TrafficLightState.red);
				_count = 0;
				_elapsedTime = 0;
			}
		}
	}

	@Override
	public boolean isCompatibleWith(TrafficLight trafficLight) 
	{
		if(trafficLight.getLaneType() == LaneType.SIDEWALK_LEFTSIDE) return true;
		if(trafficLight.getLaneType() == LaneType.SIDEWALK_RIGHTSIDE) return true;
		return false;
	}
	
}
